<?php
ini_set("error_reporting","E_ALL & ~E_NOTICE");
$text=$_POST["text"];$text = preg_replace('# #','',$text);

if (strstr($text,"S/") or strstr($text,"s/")){
    $text = str_replace("S/"," ",$text);
    $text = str_replace("s/"," ",$text);
    $text = preg_replace('# #','',$text);
}

if (!$text) {
    die(json_encode($data['status']="NO"));
}

$servername = "localhost";
$username = "username";//需要修改为你的 数据
$password = "password";
$dbname = "dbname";

$con = new mysqli($servername, $username, $password, $dbname);
if (mysqli_connect_errno()){// 检测连接-失败回传钉钉信息
    mysqli_close($con);//关闭数据库
    $data['status']="NO";
    $data['message']="链接数据库失败，请稍候刷新重试！";
    echo json_encode($data);
}else{//读取记录数据
    $sql = "SELECT * FROM `url` WHERE `description` like '%$text%' or `keywords` like '%$text%' or `title` like '%$text%'";
    $result = $con->query($sql);
    if ($result->num_rows > 0) {$i=0;
        while($row = $result->fetch_assoc()) {
            $data["url"][$i]["title"] = $row["title"];
            $data["url"][$i]["url"] = $row["url"];
            $data["url"][$i]["logo"] =  "./icon/".$row["title"].".png";
            $data["url"][$i]["descriptions"] = $row["description"];
            $i++;
        }
        echo json_encode($data);
    } else {
        $data['status']="NO";
        $data['message']="数据表中未查询到任何数据！";
        echo json_encode($data);
    }
    $con->close();//关闭数据库
}
?>